package com.bjpowernode.shop.config;

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializer;

/*
    Redis在进行存储时，可以指定存储的格式为json，默认是二进制的格式
 */
@Configuration
//开启SpringCache的注解缓存，必须配置redis的信息
@EnableCaching
public class RedisValueConfig {

    @Bean
    public RedisCacheConfiguration redisCacheConfiguration() {
        //获取redis默认的缓存配置信息
        RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
        //设置redis存储时的value格式为json格式
        redisCacheConfiguration = redisCacheConfiguration.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.json()));
        return redisCacheConfiguration;
    }

}
